package cn.itlaobing.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import cn.itlaobing.entity.Student;
import cn.itlaobing.entity.enums.Gender;
import cn.itlaobing.service.StudentService;

@Controller("/students/add")
public class StudentAdd extends BaseController {

	Log log = LogFactory.getLog(StudentAdd.class);

	@Autowired
	private StudentService studentService;

	// 获取表单
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Student student = new Student();
		request.setAttribute("student", student);
		request.setAttribute("genders", Gender.values());
		toView("/students/add.jsp", request, response);
	}
	
	//保存
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String name = request.getParameter("name");
		String gender = request.getParameter("gender");
		String birthday = request.getParameter("birthday");
		studentService.add(name, gender, birthday);
		redirectTo("/students/home",request,response);
	}

}
